<template>
  <!-- 头部导航栏组件 -->
  <div class="header wrap">
    <div class="login_img">
      <img src="@/assets/img/indexLogo.6f8ac4f0.png" alt="" />
    </div>

    <ul class="nvas">
      <li
        :class="{ nvas_l1: route.path == '/home' }"
        @click="router.push('/home')"
      >
        首页
      </li>
      <li
        :class="{ nvas_l1: route.path == '/goods' }"
        @click="router.push('/goods')"
      >
        全部商品
      </li>
      <li
        :class="{ nvas_l1: route.path == '/user/cart' }"
        @click="router.push('/user')"
      >
        个人中心
      </li>
      <li
        :class="{ nvas_l1: route.path == '/order' }"
        @click="router.push('/order')"
      >
        我的订单
      </li>
      <li
        :class="{ nvas_l1: route.path == '/free' }"
        @click="router.push('/free')"
      >
        专属福利
      </li>
    </ul>

    <div class="search">
      <input type="text" placeholder="请输入关键字" v-model="keyword" />
      <span @click="toGoods">
        <img class="search_img" src="@/assets/img/search.png" alt="" />
      </span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
const keyword = ref("");
const toGoods = () => {
  //点击搜索图标跳转到全部商品goods页面并携带搜索关键字
  if (!keyword.value.trim()) return;
  router.push(`/goods?keyword=${keyword.value}`);
  keyword.value = ""; //清空输入框
};
</script>

<style lang="less" scoped>
.header {
  height: 118px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-family: SourceHanSansSC;
  font-weight: 500;
  .login_img {
    margin-bottom: 10px;
  }
  .nvas {
    display: flex;
    justify-content: space-between;
    width: 500px;
    li {
      &.nvas_l1 {
        color: #0a328e;
        font-weight: 700;
        cursor: pointer;
      }
    }
  }
  .search {
    height: 40px;
    input[type="text"] {
      width: 214px;
      height: 40px;
      border: 1px solid #dedede;
      border-radius: 20px 0px 0px 20px;
      outline: none;
      padding-left: 14px;
    }
    span {
      display: inline-block;
      width: 50px;
      height: 44px;
      background: #0a328e;
      border-radius: 0px 20px 20px 0px;
      vertical-align: middle;
      text-align: center;
      .search_img {
        height: 40px;
        transform: scale(0.46);
      }
    }
  }
}
</style>
